package place;
import java.util.Scanner;

import PJ.Entrance;
import PJ.Player;

public  class House extends  Land {
	House(int x, int y,String name,int price) {
		this.i = x;
		this.j = y;		
		this.name=name;
		this.price=price;
		this.intialprice=price;
	}

	@Override
	public char getchart() {
	if(this.owner==1){
		return '○';
	}else if(this.owner==2){
		return '●';
	}else if(this.owner==3){
		return '▽';
	}else if(this.owner==4){
		return '▼';
	}else{
		return '◎';
	}
	}
	//�鿴��Ϣ
	public void printInformation(int step){
		System.out.println("这里是"+"玩家"+this.owner+"的房产，价值"+this.price);
	}
	@Override	
	public void printaction(int step,int namei){
		Player player=new Player();
		Player playerow=new Player();
		for(int i=0;i<Entrance.players.size();i++){
			if(Entrance.players.get(i).getNamei()==namei){
				player=Entrance.players.get(i);
			}
			if(Entrance.players.get(i).getNamei()==owner){
				playerow=Entrance.players.get(i);
			}
		}
		System.out.println("这里是"+this.name);
		if(this.owner==0){
			System.out.println("是否购买这块土地？这将花费您"+this.price+"\n"+"是请输入y，不是请输入n");
			Scanner input=new Scanner(System.in);
			String answer=input.next();
			while(true){
			if(answer.equals("y")){
				if(player.getCash()>=this.price){
				this.owner=player.getNamei();
				player.setCash(player.getCash()-this.price);
				System.out.println("支付成功，"+this.name+"是您的了!");
				player.setHousequantity(player.getHousequantity()+1);
				player.setHouseValue(player.getHouseValue()+this.price);
				}else{
				System.out.println("您的现金不足，本地不支持刷卡");
				}
				break;
			}else if(answer.equals("n")){
				System.out.println("真是遗憾，但是今晚您可以免费住在这里");
				break;
			}else{
				System.out.println("不合法的输入！");
				answer=input.next();
			}
			}
		}else if(this.owner==namei){
			if(this.level<3){
				System.out.println(this.name+"的土地级别为"+this.level+"您要升级么？"+"\n"+"是请输入y，不是请输入n");
				Scanner in=new Scanner(System.in);
				String ans=in.next();
				if(ans.equals("y")){
					if(player.getCash()>this.price*0.5){
					player.setCash(player.getCash()-this.price*0.5);
					player.setHouseValue(player.getHouseValue()+this.price*0.5);
					this.level++;
					this.price*=1.5;
					System.out.println("支付成功，您的"+this.name+"升级了!"+"当前等级"+this.level+"级");
					}
					else{
					System.out.println("您的现金不足，本地不支持刷卡");
					}		
				}else{
					System.out.println("真遗憾，您的土地仍为"+this.level+"级");
				}
			}else{
					System.out.println("您的土地已到最高级别吗");
				}
		}else{
			System.out.println("您来到了玩家"+this.owner+"的"+this.name);
			System.out.println("您需要支付"+this.price+"的寄宿费");
			if(player.getCash()>this.price){
				player.setCash(player.getCash()-this.price);
				playerow.setDeposit(playerow.getDeposit()+this.price);					
				}else{
				player.setDeposit(player.getDeposit()+player.getCash());					
				player.setCash(0);
				player.setDeposit(player.getDeposit()-this.price);	
				playerow.setDeposit(playerow.getDeposit()+this.price);					
				if(player.getDeposit()<0&&player.getHouseValue()>0){				
					System.out.println(player.getName()+"资金不足，进入房产抵押环节");	
					for(int m=0;m<=67;m++){
						if(Landindex.mark[m].owner==namei){
							Landindex.mark[m].owner=0;
							player.setDeposit(player.getDeposit()+Landindex.mark[m].price);
							System.out.println(player.getName()+"的价值"+Landindex.mark[m].price+"的房产已经出售给银行");	
							if(player.getDeposit()>0){
								break;
							}
						}
					}
				}else{
					System.out.println("您破产了，祝您下次游戏愉快~~");
					if(Entrance.players.size()==1){
						System.out.println("胜利的玩家是:"+Entrance.players.get(0).getName());
						System.exit(0);
					}
					for(int i=0;i<Entrance.players.size();i++){
						if(Entrance.players.get(i).getNamei()==namei){
							Entrance.players.remove(i);
						}
					}
					for(int m=0;m<=67;m++){
						if(Landindex.mark[m].owner==namei){
							Landindex.mark[m].owner=0;								
						}
					}
				}
			}
		}
	}	
	public char getinitialchart() {
		return '◎';
		// TODO Auto-generated method stub
	}
}


